#!/bin/bash

#---------------------------------------------------------------------
# Script  : postlight
#---------------------------------------------------------------------
# Purpose : Script that end the full installation 
#---------------------------------------------------------------------
# History :
#
# 12/2004 LS Creation
#---------------------------------------------------------------------

echo 'KDIS INSTALLER - START POSTFLIGHT SCRIPT'

# Echoes the script arguments
echo "The full path to the install package : $1"
echo "The full path to the install destination : $2"
echo "The mount point of the destination volume : $3"
echo "The root directory for the current system folder : $4"

target="$2Applications/KDIS Mac OS X"

#Check the KDIS installation
if [ -e "$target"/'KDIS' ] ; then
   (cd "$target" && chown root:admin 'KDIS' && chmod 777 'KDIS')
   echo 'The KDIS application is successfully installed'
else
   echo 'Fail to install the KDIS application'
   exit 1
fi

# Check the Registry.bundle installation
if [ -e '/Library/Registry.bundle' ] ; then
	echo 'The Registry.bundle bundle is successfully installed'
else
	echo 'Fail to install the Registry.bundle bundle'
	exit 1
fi

# Check the xray.bundle installation
if [ -e '/Library/xray.bundle' ] ; then
	echo 'The xray.bundle bundle is successfully installed'
else
	echo 'Fail to install the xray.bundle bundle'
	exit 1
fi

# Modify the current /etc/smb.conf to allow file sharing 
# over a network 

# Search for a previous installation
 cat /etc/smb.conf | grep -q "\[KDIS\]"

#install
if [ $? -eq 1 ]
then
# $? Exit status return 1 first installation  
# Adding Kodak file sharing configuration to /etc/smb.conf

  echo "

  #This section establishes the file sharing between Mac and Windows workstations
  #It must not be removed or modified
  [Kodak]
  path = /Users/%u/Public/Kodak
  comment = Kodak Repository

  browsable = yes
  writeable = yes

  create mask = 0666
  directory mask = 0777

  " >> /etc/smb.conf

#reboot servers
killall -HUP smbd
killall -HUP nmbd

echo 'The smb coniguration file has been successfully modified'

else
# $? Exit status return 0 if a previous installation of KDIS had been made  
echo 'The smb coniguration file has been already modified'
fi

#remove the Resources temporary folder
if [ -e "$2/Resources" ] ; then
   (rm -R "$2/Resources")
   echo 'The Resources temporary folder is successfully removed'
fi

echo 'KDIS INSTALLER - END POSTFLIGHT SCRIPT'

exit 0
